package pers.mihao.quickstream.common.task.scheduler;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import pers.mihao.quickstream.common.task.constans.SchedulerCenterType;
import pers.mihao.quickstream.common.task.scheduler.annotation.EnableSchedulerTask;
import pers.mihao.quickstream.common.task.scheduler.isolated.IsolatedAutomaticTaskScheduler;


/**
 * @author mihao
 * @since 2024/11/18
 */
public class AutomaticTaskSchedulerConfig implements ImportSelector {


    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        AnnotationAttributes annoAttrs = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableSchedulerTask.class.getName()));
        if (annoAttrs == null) {
            return new String[]{};
        }
        SchedulerCenterType type = (SchedulerCenterType) annoAttrs.get("type");
        if (type == SchedulerCenterType.isolated) {
            return new String[]{IsolatedAutomaticTaskScheduler.class.getName()};
        }
        return new String[]{};
    }
}
